<div id="result">
<?php echo $this->Session->flash(); ?>
<div class="div_header1">Manage Labels</div>
<form method="post" id="global_brand" name="global_brand" action="<?php echo Configure::read('base_url')."add_category/add_manage_labels/";?>">
<br style="clear:both;">
<table width="100%" cellspacing="0" id="brandstable">
<?php 
if($labels):
$i=0;
foreach ($labels as $label):
	$class = null;
	if ($i++ % 2 == 0)
	$class = ' class="alt"';	
	?> 
  <tr>
	<td width="88" <?php echo $class;?>><?php echo $label['Label']['id']; ?></td>
	<td width="92" <?php echo $class;?>><span id="inputbox_<?php echo $label['Label']['id'];?>"><?php echo $label['Label']['label_name'];?></span></td>
	<td width="90" <?php echo $class;?>><span id="savebutton_<?php echo $label['Label']['id'];?>">
	<a href="javascript:void(0);" class="clickToEdit" title="Click here to edit <?php echo $label['Label']['label_name'];?>" entryID="<?php echo $label['Label']['id'];?>">Edit</a>
	 | 
	<a href="javascript:void(0);" onclick="return deleteconfirm(this);" controller="add_category" action="delete_manage_labels" title="Delete" ElmID="<?php echo $label['Label']['id'];?>" ElmID2="<?php echo $label['Label']['category_id'];?>">Delete</a>
	</span>
	<span id="showsave_<?php echo $label['Label']['id']; ?>"></span>
	</td>
  </tr>
  <?php endforeach;else:?>
  <tr>
	<td class="alt"><b>No labels found for this category. Use the following input box to create labels for this category.</b></td>
  </tr>
  <?php endif;?>
  
</table> 
<a onclick="showPop(this)" elmid="<?php echo $category['Category']['id'];?>" action="fields" controller="add_category" href="javascript:void(0);">Back to additional fields</a>
<table width="100%" id="add_global_form" border="0" cellspacing="0" cellpadding="0">
  <tr>
	<td class="alt" width="144">
		<input type="hidden" name="data[category_id]" value="<?php echo $category['Category']['id'];?>">
		<input type="index" id='description' name="data[label_name]" size="30" class="required" value="Enter label here" onblur="if(this.value=='') this.value='Enter label here'" onfocus="if(this.value=='Enter label here') this.value='';"/>
		<div id="loader" style="display:none;"><img src="<?php echo Configure::read('base_url');?>img/loading.gif" alt="loading..." /></div>
	</td>
	<td width="347" class="alt" valign="top">
		<input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="Save" id="Save" value="Save" />		
	</td>
	
  </tr>
</table>
       
<div class="div_bottom1"></div>
</form>
</div>
<?php echo $html->script(array("jquery.min.js","jquery.form.js","jquery.validate.js","jquery.pagination.js","jquery.tablesorter.min.js","jquery.tablednd.js")); ?>	 
 <script type="text/javascript">  
 jQuery.noConflict();

 jQuery(document).ready(function(){
 jQuery("#category_table").tablesorter({headers: { 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}}); 
 
		var v = jQuery("#global_brand").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#result"
				});
			}
		});
		
	jQuery("form#global_brand a.clickToEdit").click(function()
		{
			if(jQuery(this).attr('class')=='clickToEdit'){
				var entryID=(jQuery(this).attr("entryID"));
				var inputValue=jQuery("#inputbox_"+entryID).html();
				
				var inputbox='<input type="hidden" value="'+entryID+'" name="data[id]"><input type="text" id="editbox_'+entryID+'" value="'+inputValue+'" name="data[label_name]"><input type="hidden" value="'+inputValue+'" name="old_description" />';
				jQuery("#inputbox_"+entryID).html(inputbox);
				
				var savebutton='<a href="javascript:void(0);" entryID="'+entryID+'" title="Save" onclick="return saveEntry(this);">Save</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);" entryID="'+entryID+'" onclick="cancelForm(this)">Cancel</a>';
				jQuery("span#savebutton_"+entryID).hide().fadeOut("slow");		
				jQuery("span#showsave_"+entryID).live("click", cancelForm).html(savebutton);	
								
				jQuery('.required').attr('disabled',true);
				jQuery('#Save').attr('disabled',true);
				
				jQuery("form#global_brand a.clickToEdit").each(function (index,domEle) {
					  jQuery(domEle).removeClass("clickToEdit"); 
					  jQuery(domEle).addClass("clickToCancel"); 
				  });
			}
			else{
				return false;
			}			
			
		});
		
	});
	
	//Global brands/Styles/Conditions edit functions
	function saveEntry(param){
		entryID=jQuery(param).attr("entryID");
		boxID="editbox_"+entryID;
		data = jQuery("#global_brand").serialize();
		inputValue=jQuery('input[id="'+boxID+'"]').val();
		jQuery('input[name="old_description"]').val(inputValue);
		//alert(data);
		jQuery.ajax({
			type: 'POST',
			url: baseurl+"add_category/edit_manage_labels/",
			data: data,
			dataType: 'json',
			success: function(data){
				if(data.message=="No"){
					alert("Label could be saved, please try again.");
				}
				if(data.message=="Yes"){
					alert("Label has been updated successfully.");
				}
				if(data.message=="Duplicate"){
					alert("Duplicate label, please try again.");
				}
				if(data.message=="Empty"){
					alert("Label cannot be left empty.");
				}
				return false;
				
				
			}
		});
		
		cancelForm(param);	
		return false;		
	}	
	
	function cancelForm(param){		
		var entryID=jQuery(param).attr("entryID");
		var boxID="editbox_"+entryID;
		var inputValue=jQuery('input[name="old_description"]').val();	
		jQuery("#inputbox_"+entryID).html(inputValue);
		jQuery("span#savebutton_"+entryID).show().fadeIn("slow");		
		jQuery("span#savebutton_"+entryID+" a").attr("class","clickToEdit");		
		jQuery("span#showsave_"+entryID).die("click", cancelForm).text("");
		
		jQuery("form#global_brand a.clickToCancel").each(function (index,domEle) {
					 jQuery(domEle).removeClass("clickToCancel"); 
					  jQuery(domEle).addClass("clickToEdit");
				  });
				  
		jQuery('.required').removeAttr('disabled');
		jQuery('#Save').removeAttr('disabled');
	}
	
	
	function deleteconfirm(param){
		if(confirm("Are you sure you want to delete it?"))
		showPop(param);
		else
		return false;
	}
</script>
 <?php //echo $this->element('sql_dump'); ?>